import pygame
import sys


def load_image_and_get_click_coordinates(image_path):
    pygame.init()

    # 加载图像
    image = pygame.image.load(image_path)
    image_size = image.get_size()  # 获取图像的大小

    # 创建一个与图像大小相同的窗口
    screen = pygame.display.set_mode(image_size)
    pygame.display.set_caption('Click on the image')  # 设置窗口标题

    # 图像位置设置为窗口左上角
    image_rect = image.get_rect(topleft=(0, 0))

    screen.blit(image, image_rect)  # 在窗口中显示图像
    pygame.display.flip()  # 刷新屏幕

    running = True
    while running:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:  # 如果点击了窗口关闭按钮，则退出程序
                running = False
            elif event.type == pygame.MOUSEBUTTONDOWN:  # 如果鼠标点击了屏幕
                mouse_pos = pygame.mouse.get_pos()  # 获取鼠标位置
                # 计算相对于图像的像素坐标
                relative_pos = (mouse_pos[0] - image_rect.left, mouse_pos[1] - image_rect.top)
                print("Clicked at:", relative_pos)

    pygame.quit()  # 退出Pygame


# 替换成你的图片路径
image_path = 'E:\Pycharm_Project\salvation-of-the-doomed-world\\resources\graphics\little_girl_yufei.png'
image_path1 = 'E:\Pycharm_Project\salvation-of-the-doomed-world\\resources\graphics\mario_bros.png'

load_image_and_get_click_coordinates(image_path)
